package net.maku.im.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.im.dto.ImGroupMessageQueryDTO;
import net.maku.im.service.ImGroupMessageService;
import net.maku.im.vo.ImGroupMessageVO;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* 群聊消息
*
* @author Blue 
* @since 1.0.0 2024-07-20
*/
@RestController
@RequestMapping("im/message/group")
@Tag(name="群聊消息")
@AllArgsConstructor
public class ImGroupMessageController {
    private final ImGroupMessageService groupMessageService;

    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("hasAuthority('im:message:group:page')")
    public Result<PageResult<ImGroupMessageVO>> page(@ParameterObject @Valid ImGroupMessageQueryDTO query){
        PageResult<ImGroupMessageVO> page = groupMessageService.page(query);
        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    @PreAuthorize("hasAuthority('im:message:group:info')")
    public Result<ImGroupMessageVO> get(@PathVariable("id") Long id){
        ImGroupMessageVO vo = groupMessageService.info(id);
        return Result.ok(vo);
    }
}